package com.lab303.powerproject.controller;


import com.lab303.powerproject.util.GenerateDemoData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("demo")
public class DemoController {


    @PostMapping("/data")
    @ResponseBody
    public Map<String, Object> getDemoData(float tem1,float tem2,Float hum1,Float hum2,int flag,int peopleNumber,int tianqi){
        Map<String, Object> combine = new HashMap<>();
        float[]  bangong= new float[]{0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,5.0f,28.0f,29.0f,30.0f,29.0f,30.0f,28.0f,29.0f,30.0f,29.0f,30.0f,30.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
        float[] zhaoming = new float[]{0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,35.0f,40.0f,40.0f,40.0f,38.0f,38.0f,37.0f,39.0f,38.0f,36.0f,30.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
        float[] xiaofang = new float[]{8.0f,9.0f,8.5f,9.5f,8.0f,9.0f,8.5f,9.5f,8.0f,9.0f,8.5f,9.5f,8.0f,9.0f,8.5f,9.5f,8.0f,9.0f,8.5f,9.5f,8.0f,9.0f,8.5f,9.5f};
        float[] other = new float[]{0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,8.0f,9.0f,8.5f,9.5f,8.0f,9.0f,8.5f,9.5f,8.0f,9.0f,8.5f,0.0f,0.0f,0.0f,0.0f,0.0f};
        float[] guangfu;
        if (tianqi==1){
            guangfu = new float[]{0f,0f,0f,0f,0f,0f,2.9f,12f,21.6f,29.5f,34.7f,37.3f,37.2f,33.2f,23.1f,14f,4.7f,0.3f,0f,0f,0f,0f,0f,0f};
        }else {
            guangfu = new float[]{0f,0f,0f,0f,0f,0f,0f,1.4f,1.9f,5.2f,8.5f,14.8f,11.8f,7.8f,4.3f,1.3f,0f,0f,0f,0f,0f,0f,0f,0f};
        }
        if (flag==0){
            if(hum1==null&&hum2==null) {
                hum1 = 20f;
                hum2 = 30f;
            }
        }else {
            if(hum1==null&&hum2==null) {
                hum1 = 50f;
                hum2 = 70f;
            }
        }
        Map<String, float[]> dataMap = GenerateDemoData.doGenerate(tem1, tem2, hum1, hum2, flag,peopleNumber);
        float[] dianneng = new float[24];
        float[] dianliangs = dataMap.get("dianliang");

        for (int i = 0 ; i < dianliangs.length;i++){
            dianneng[i] = dianliangs[i]-guangfu[i]+bangong[i]+zhaoming[i]+xiaofang[i]+other[i];
            dianneng[i] = new BigDecimal(dianneng[i]).setScale(1,BigDecimal.ROUND_HALF_UP).floatValue();
        }
        combine.put("dianneng",dianneng);
        combine.put("guangfu",guangfu);
        combine.putAll(dataMap);
        return combine;
    }


}
